import SwiftUI
import SPGlassKit

public struct GlassProgressExample: GlassExample {
    public static let componentID = "glass-progress"
    @State private var uploaded = 30.0
    @State private var isCancelled = false

    public init() {}

    public var body: some View {
        VStack(alignment: .leading, spacing: 20) {
            if isCancelled {
                Text("Upload cancelled").foregroundStyle(.secondary)
            } else {
                GlassProgress("Uploading sample.pdf", value: uploaded, total: 120, onCancel: { isCancelled = true })
            }
            GlassProgress("Storage used", value: 0.82, style: .circular)
            GlassProgress("Connecting")
            GlassProgress(style: .circular)
            HStack(spacing: 24) {
                GlassProgress("Storage", value: 0.82, style: .ring)
                GlassProgress("Battery", value: 0.46, style: .ring)
            }
            GlassProgress("Shipping address", step: 2, of: 4)
            HStack {
                GlassButton("Add 30 MB") { uploaded += 30 }
                GlassButton("Restart") {
                    uploaded = 0
                    isCancelled = false
                }
            }
        }
        .padding()
    }
}

#Preview("GlassProgress") { GlassProgressExample() }
